package com.hxkj.service.taglib.impl;

import com.hxkj.client.service.ColumnServiceClient;
import com.hxkj.client.service.GeneratorStaticFileServiceClient;
import com.hxkj.client.service.TagsServiceClient;
import com.hxkj.domain.po.Article;
import com.hxkj.domain.po.Column;
import com.hxkj.domain.po.Tags;
import com.hxkj.service.taglib.AnakyzeFreeMakerService;
import com.platform.common.domain.exception.CustomMessageException;
import com.platform.common.domain.result.ResultMessageStruct;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName CreateFreeMakerColumnServiceImpl
 * @Description TODO
 * @Author Mr.zheng
 * @Date 2018/8/2 10:46
 * @Version 1.0
 */
@Service
@Slf4j
public class AnakyzeFreeMakerServiceImpl implements AnakyzeFreeMakerService {

    @Autowired
    private ColumnServiceClient columnServiceClient;

    @Autowired
    private TagsServiceClient tagsServiceClient;

    @Autowired
    private GeneratorStaticFileServiceClient generatorStaticFileServiceClient;

    @Override
    public void createFreeMakerColumn(Column column) throws Exception {
        try {
            List<Column> columnList = columnServiceClient.getColumnListByTerms(column);
            if (columnList != null && columnList.size() != 0) {
                generatorStaticFileServiceClient.GenColumnFile(columnList);
            }

        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }


    /**
     * 这里需要实现websocket进度条
     *
     * @param article
     * @return
     * @throws Exception
     */
    @Override
    public void createFreeMakerArticle(Article article) throws Exception {
        ResultMessageStruct resultMessageStruct = generatorStaticFileServiceClient.generateArticleHTML(article);
        if (resultMessageStruct.getCode() != 200) {
            throw new CustomMessageException(400, resultMessageStruct.getMessage());
        }

    }

    @Override
    public void createFreeMakerTagArticle(Tags tag) throws Exception {
        try {
            List<Tags> tagsList = tagsServiceClient.getShowTagsList(tag);

            if (tagsList != null && tagsList.size() != 0) {
                generatorStaticFileServiceClient.GenTagInfoFile(tagsList);
            }
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }
}
